<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input />
    <script>
        var box = document.querySelector('input');
        // 获取焦点 改变背景颜色
        box.onfocus = function () {
            box.style.background = '#0f0';
        };
        // 失去焦点判断内容
        box.onblur = function () {
            if (box.value == '') {
                alert('请输入正确的内容');
                box.style.background='#f00';
            }else{
                box.style.background='#fff';
            }
        }
        // 当值发生改变时判断内容
        box.onchange = function () {
            if (box.value == 'admin') {
                alert('填写的值不能为admin');
            }
        }
    </script>
</body>

</html>